﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using System.IO;

namespace App1AppHandler
{
    public class SpellPage
    {
        public int PageNumber = -1;
        public SpellIcon[] SpellIcons = new SpellIcon[12];

        public string toXML()
        {
            string result = "";

            StringWriter stringWriter = new StringWriter();
            XmlTextWriter xmldoc = new XmlTextWriter(stringWriter);

            xmldoc.WriteStartElement("spellpage");
            xmldoc.WriteAttributeString("PageNumber", PageNumber.ToString());

            string innerXml = "";
            for (int ctr = 0; ctr < 12; ctr++)
            {
                if (SpellIcons[ctr] != null)
                    innerXml = innerXml + SpellIcons[ctr].toXML();
                else
                    innerXml = innerXml + "<spellicon />";
            }
            xmldoc.WriteStartElement("SpellIcons");
            xmldoc.WriteRaw(innerXml);
            xmldoc.WriteEndElement();

            xmldoc.WriteEndElement();
            xmldoc.Flush();

            xmldoc.Close();

            stringWriter.Flush();

            result = stringWriter.ToString();

            return result;
        }
    }
}
